{% extends "admin/base.html" %}

{% block admin_content %}
<div class="row">
    <!-- 统计卡片 -->
    <div class="col-xl-3 col-md-6 mb-4">
        <div class="card border-left-primary shadow h-100 py-2">
            <div class="card-body">
                <div class="row no-gutters align-items-center">
                    <div class="col mr-2">
                        <div class="text-xs font-weight-bold text-primary text-uppercase mb-1">
                            总题目数</div>
                        <div class="h5 mb-0 font-weight-bold text-gray-800">{{ questions|length }}</div>
                    </div>
                    <div class="col-auto">
                        <i class="bi bi-question-circle fa-2x text-gray-300"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="col-xl-3 col-md-6 mb-4">
        <div class="card border-left-success shadow h-100 py-2">
            <div class="card-body">
                <div class="row no-gutters align-items-center">
                    <div class="col mr-2">
                        <div class="text-xs font-weight-bold text-success text-uppercase mb-1">
                            总抽题次数</div>
                        <div class="h5 mb-0 font-weight-bold text-gray-800">{{ draw_count }}</div>
                    </div>
                    <div class="col-auto">
                        <i class="bi bi-shuffle fa-2x text-gray-300"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="col-xl-3 col-md-6 mb-4">
        <div class="card border-left-info shadow h-100 py-2">
            <div class="card-body">
                <div class="row no-gutters align-items-center">
                    <div class="col mr-2">
                        <div class="text-xs font-weight-bold text-info text-uppercase mb-1">
                            每次抽题数</div>
                        <div class="h5 mb-0 font-weight-bold text-gray-800">{{ configs.get('questions_per_draw', 1) }}</div>
                    </div>
                    <div class="col-auto">
                        <i class="bi bi-list-ol fa-2x text-gray-300"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="col-xl-3 col-md-6 mb-4">
        <div class="card border-left-warning shadow h-100 py-2">
            <div class="card-body">
                <div class="row no-gutters align-items-center">
                    <div class="col mr-2">
                        <div class="text-xs font-weight-bold text-warning text-uppercase mb-1">
                            最大重抽次数</div>
                        <div class="h5 mb-0 font-weight-bold text-gray-800">{{ configs.get('retry_limit', 3) }}</div>
                    </div>
                    <div class="col-auto">
                        <i class="bi bi-arrow-repeat fa-2x text-gray-300"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 快捷操作卡片 -->
<div class="row">
    <div class="col-lg-6 mb-4">
        <div class="card shadow mb-4">
            <div class="card-header py-3">
                <h6 class="m-0 font-weight-bold text-primary">快捷操作</h6>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-6 mb-3">
                        {% if current_user.is_super_admin() %}
                        <a href="{{ url_for('admin.questions') }}" class="btn btn-primary btn-block">
                            <i class="bi bi-question-circle me-2"></i>管理题库
                        </a>
                        {% else %}
                        <button class="btn btn-primary btn-block" disabled>
                            <i class="bi bi-question-circle me-2"></i>管理题库
                        </button>
                        {% endif %}
                    </div>
                    <div class="col-md-6 mb-3">
                          {% if current_user.is_super_admin() %}
                        <a href="{{ url_for('admin.config') }}" class="btn btn-info btn-block">
                            <i class="bi bi-gear me-2"></i>修改配置
                        </a>
                        {% else %}
                        <button class="btn btn-info btn-block" disabled>
                             <i class="bi bi-gear me-2"></i>修改配置
                        </button>
                        {% endif %}
                    </div>
                    <div class="col-md-6 mb-3">
                        {% if current_user.is_super_admin() %}
                        <a href="{{ url_for('admin.statistics') }}" class="btn btn-success btn-block">
                            <i class="bi bi-bar-chart me-2"></i>查看统计
                        </a>
                        {% else %}
                        <button class="btn btn-success btn-block" disabled>
                            <i class="bi bi-bar-chart me-2"></i>查看统计
                        </button>
                        {% endif %}
                    </div>
                    <div class="col-md-6 mb-3">
                         {% if current_user.is_super_admin() %}
                        <a href="{{ url_for('admin.export_questions') }}" class="btn btn-warning btn-block">
                            <i class="bi bi-download me-2"></i>导出题目
                        </a>
                         {% else %}
                        <button class="btn btn-warning btn-block" disabled>
                            <i class="bi bi-download me-2"></i>导出题目
                        </button>
                         {% endif %}
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="col-lg-6 mb-4">
        <div class="card shadow mb-4">
            <div class="card-header py-3">
                <h6 class="m-0 font-weight-bold text-primary">使用说明</h6>
            </div>
            <div class="card-body">
                <div class="list-group list-group-flush">
                    <div class="list-group-item">
                        <i class="bi bi-check-circle-fill text-success me-2"></i>
                        在"题库管理"中可以添加、编辑、删除题目
                    </div>
                    <div class="list-group-item">
                        <i class="bi bi-check-circle-fill text-success me-2"></i>
                        支持Excel导入导出题目
                    </div>
                    <div class="list-group-item">
                        <i class="bi bi-check-circle-fill text-success me-2"></i>
                        在"系统配置"中可以设置每次抽题数量和最大重抽次数
                    </div>
                    <div class="list-group-item">
                        <i class="bi bi-check-circle-fill text-success me-2"></i>
                        在"数据统计"中可以查看每道题的被抽取次数
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 系统信息卡片 -->
<div class="row">
    <div class="col-lg-12 mb-4">
        <div class="card shadow mb-4">
            <div class="card-header py-3">
                <h6 class="m-0 font-weight-bold text-primary">系统信息</h6>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-6">
                        <div class="table-responsive">
                            <table class="table table-bordered">
                                <tr>
                                    <th style="width: 30%">系统版本</th>
                                    <td>1.0.0</td>
                                </tr>
                                <tr>
                                    <th>Python版本</th>
                                    <td>{{ platform_module.python_version() }}</td>
                                </tr>
                                <tr>
                                    <th>Flask版本</th>
                                    <td>2.0.1</td>
                                </tr>
                                <tr>
                                    <th>数据库</th>
                                    <td>MySQL 8.0</td>
                                </tr>
                                <tr>
                                    <th>最后编译日期</th>
                                    <td>20250413</td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="table-responsive">
                            <table class="table table-bordered">
                                <tr>
                                    <th style="width: 30%">服务器时间</th>
                                    <td>{{ now.strftime('%Y-%m-%d %H:%M:%S') }}</td>
                                </tr>
                                <tr>
                                    <th>服务器系统</th>
                                    <td>{{ platform_module.platform() }}</td>
                                </tr>
                                <tr>
                                    <th>服务器CPU</th>
                                    <td>{{ platform_module.processor() }}</td>
                                </tr>
                                <tr>
                                    <th>服务器内存</th>
                                    <td>{{ (psutil_module.virtual_memory().total / (1024*1024*1024))|round(2) }} GB</td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block styles %}
    <link rel="stylesheet" href="{{ url_for('static', filename='css/admin.css') }}">
{% endblock %} 